﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace sy4_5
{
    public partial class Form1 : Form
    {
        int i = 0; // 控制图片切换的变量

        public Form1()
        {
            InitializeComponent();
        }

        // 窗体载入事件：初始化蝴蝶图片
        private void Form1_Load(object sender, EventArgs e)
        {
         
            // 可选：设置窗体背景图
            // this.BackgroundImage = Image.FromFile("flower.jpg");
        }

        // 按钮点击事件：控制蝴蝶飞舞的开始/停止
        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == false)
            {
                button1.Text = "停止";
                timer1.Enabled = true; // 启动时钟
            }
            else
            {
                button1.Text = "开始";
                timer1.Enabled = false; // 停止时钟
                i = 0; // 重置状态
                pictureBox1.Image = Image.FromFile("bfly2.png");
            }
        }

        // 时钟Tick事件：交替切换蝴蝶图片
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (i % 2 == 0)
            {
                pictureBox1.Image = Image.FromFile("bfly1.png");
            }
            else
            {
                pictureBox1.Image = Image.FromFile("bfly2.png");
            }
            i++;
        }
    }
}